﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Hi_Baidu.ProcessModel;

namespace Hi_Baidu.Timer
{
    /// <summary>
    ///     提供了更新挂起的用户新数据, 到服务器操作的计时操作和后续处理
    /// </summary>
    class UpdateChanageUserInfo_TimeOutEvent : TimeOutEvent
    {
        private Win_ModifyUserInfo win_ModifyUserInfo;
        private byte[] username;
        private byte[] DB_FILED;
        private byte[] NEW_VALUE;

        /// <summary>
        ///     提供了更新挂起的用户新数据, 到服务器操作的计时操作和后续处理
        /// </summary>
        /// <param name="win_Main" type="Hi_Baidu.Win_Main">
        ///     <para>
        ///         主面板句柄
        ///     </para>
        /// </param>
        /// <param name="username" type="string">
        ///     <para>
        ///         用户名
        ///     </para>
        /// </param>
        /// <param name="DB_FILED" type="string">
        ///     <para>
        ///         数据库关联字段
        ///     </para>
        /// </param>
        /// <param name="NEW_VALUE" type="string">
        ///     <para>
        ///         要更新的新值
        ///     </para>
        /// </param>
        /// <param name="Key" type="string">
        ///     <para>
        ///         唯一标示
        ///     </para>
        /// </param>
        /// <param name="Interval" type="int">
        ///     <para>
        ///         触发间隔
        ///     </para>
        /// </param>
        /// <param name="TryCount" type="int">
        ///     <para>
        ///         重试次数
        ///     </para>
        /// </param>
        public UpdateChanageUserInfo_TimeOutEvent(Win_ModifyUserInfo win_ModifyUserInfo, byte[] username, byte[] DB_FILED, byte[] NEW_VALUE, String Key, int Interval, int TryCount) 
            : base(Key,Interval,TryCount)
        {
            this.win_ModifyUserInfo = win_ModifyUserInfo;
            this.username = username;
            this.DB_FILED = DB_FILED;
            this.NEW_VALUE = NEW_VALUE;
            this.OnTryFull += new EventHandler<EventArgs>(UpdateChanageUserInfo_TimeOutEvent_OnTryFull);
            this.OnTick += new EventHandler<EventArgs>(UpdateChanageUserInfo_TimeOutEvent_OnTick);
        }

        void UpdateChanageUserInfo_TimeOutEvent_OnTick(object sender, EventArgs e)
        {
            //重试更新挂起操作
            UpdateProcessModel.UpdateUserChange(this.win_ModifyUserInfo, this.username, this.DB_FILED, this.NEW_VALUE);
        }

        void UpdateChanageUserInfo_TimeOutEvent_OnTryFull(object sender, EventArgs e)
        {
            //超时后
            System.Windows.Application.Current.Dispatcher.Invoke(
                System.Windows.Threading.DispatcherPriority.Background, 
                new PUBLIC_DELEGATE(Globle.ShowWindow)
                );
        }
    }
}
